#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/**
 * C语言读取文件，对字符串的存储
 * */


int main(){
    char train_file[100];
    char word[100];
    strcpy(train_file, "test.txt");
    FILE *fio;
    fio = fopen(train_file, "rb");
    char *all_words[100];
    if(fio==NULL){
        printf(" file %s not found \n", train_file);
        exit(1);
    }
    int total_count = 0;
    int ch ;
    int a = 0;
    while(!feof(fio)){
        ch = fgetc(fio);
        if((ch ==' ')|| (ch=='\n') || (ch=='\t')||(a>100)){
            word[a] = 0;
            printf("%s\n", word);
            all_words[total_count] = word;
            total_count++;
            a = 0;
            continue;
        }
        word[a] = ch;
        a++;
    }

    printf("指针数组:\n");
    for (a = 0; a < total_count; a++){
        if(all_words[a]){
            printf("%d\n", a);
            printf("%s\n",all_words[a]);
        }
    }
}
